package com.gitee.xmhzzz.component.shutdown.graceful.tomcat;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.Ordered;

/**
  * @ClassName
  * @Description
  * @Author wzq
  * @Date 2023/12/15 15:49
  * @Version 1.0
  */
@Slf4j
public class GracefulShutdownTomcatInitializer implements WebServerFactoryCustomizer<ConfigurableWebServerFactory>, Ordered {
    private final TomcatShutdown tomcatShutdown;

    public GracefulShutdownTomcatInitializer(TomcatShutdown tomcatShutdown) {
        this.tomcatShutdown = tomcatShutdown;
    }

    @Override
    public void customize(ConfigurableWebServerFactory factory) {
        TomcatServletWebServerFactory f = (TomcatServletWebServerFactory) factory;
        f.addConnectorCustomizers(tomcatShutdown);
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
